package com.ruoyi.system.controller;

import java.io.IOException;

public class AudioConverter {
    public static void convertPcmToMp3(String pcmFilePath, String mp3FilePath) {
        ProcessBuilder processBuilder = new ProcessBuilder(
                "ffmpeg",
                "-f", "s16be", // PCM格式
                "-ar", "11025", // 采样率
                "-ac", "1", // 音频通道
                "-i", pcmFilePath, // 输入文件
                mp3FilePath); // 输出文件

        try {
            Process process = processBuilder.start();
            int exitCode = process.waitFor();
            if (exitCode != 0) {
                System.err.println("Error occurred during audio conversion.");
            } else {
                System.out.println("Conversion completed successfully.");
            }
        } catch (IOException | InterruptedException e) {
            e.printStackTrace();
        }
    }
//
//    public static void main(String[] args) {
//        convertPcmToMp3("input.pcm", "output.mp3");
//    }
}
